package su.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import su.demo.annotaition.DataSource;
import su.demo.dao.StudentMapper;
import su.demo.dao.TeacherMapper;
import su.demo.entity.Student;
import su.demo.entity.Teacher;
import su.demo.enums.DataSourceEnum;
import su.demo.service.StudentService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author SuZuQi
 * @title: StudentServiceImpl
 * @projectName ssm_multipledatasources
 * @description: TODO
 * @date 2019/9/6
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper  studentMapper ;



    @Override
    @DataSource(DataSourceEnum.DEMO1)
    public int addStudent() {
       try{
           for (int i = 1; i < 11; i++) {
               Student student = new Student(i + "", "测试学生" + i, "这是测试学生" + i);
               studentMapper.addStudent(student);
           }
           return 1 ;
       }catch(Exception e){
           return 0 ;
       }
    }

    @Override
    @DataSource(DataSourceEnum.DEMO1)
    public List<Student> queryStudents() {
        return   studentMapper.queryList() ;
    }
}
